<?php
require_once(dirname(__FILE__) . '/app.php');

if(!$INI['db']['host']){
	redirect( WEB_ROOT . '/install.php' );
}


$tmp_date=date("YmdHi");
$tmp_year=substr($tmp_date,0,4) * 1;
$tmp_mon =substr($tmp_date,4,2) * 1;
$tmp_day = substr($tmp_date, 6, 2) * 1;
$tmp_Hour = substr($tmp_date, 8, 2) * 1;
$tmp_Minute = substr($tmp_date, 10, 2) * 1;

$searchDate = $_GET['search_date'];
$getDateArray = array();
if( preg_match("#/#", $searchDate) ){
	$getDateArray = explode("/", $searchDate);
}else if( preg_match("#-#", $searchDate) ){
	$getDateArray = explode("-", $searchDate);
}else{
	array_push($getDateArray, substr($searchDate, 0, 4));
	array_push($getDateArray, substr($searchDate, 4, 2));
	array_push($getDateArray, substr($searchDate, 6, 2));
}

$year = $getDateArray[0] * 1;
$month = $getDateArray[1] * 1;
$day = $getDateArray[2] * 1;

$year = $year < 1 ? $tmp_year : $year;
$month = $month < 1 ? $tmp_mon : $month;
$day = $day < 1 ? $tmp_day : $day;


$staffList = array();
$defaultShopId = $_GET['shop_id'];
if( $defaultShopId < 1 ){
	$staffList = Staff::GetAll();
}else{
	$staffList = Staff::GetAllByShop($defaultShopId);
}

$shopList = Shop::GetAllShops();


$workStaffList = array();
foreach ($staffList as $k => $v){
	$workList = WorkSchedule::GetByPeriod($year, $month, $day, $day, $v['id']);
	if( $workList != null ){
//		Logs::setLog($v['id']."sdfsfljsldfjldsjl");
		array_push($workStaffList, $v);
	}
}

if( $_GET['id'] > 0 ){
	$staff = Staff::getById($_GET['id']);
	include template('staff');
	exit;
}




include template('staff_list');
//include template('subscribe');
